
 cd E:\Stata\abd
 h xsmle           
ssc install xthreg, replace 
net get xthreg 
 use E:\Stata\abd\age-national.dta, clear  
 

clear all
cd"E:\Stata\abd"                         
xtset id year


xthreg lnco2 L.lnco2 lneng lnrd lnpgdp urb  if in, rx(ind) qx(age) thnum(1) grid(300) trim(0.01) bs(300) thlevel(95) gen(newvarname) noreg nobslog thgiven options

xthreg lnco2 L.lnco2 lneng lnrd lnpgdp urb  if in, rx(ind) qx(age) thnum(1) grid(300) trim(0.01) bs(300) thlevel(95) vce(cluster id)

xthreg lp L.lp lnpgdp lnexp urb  if in, rx(lnrd) qx(lnsep) thnum(1) grid(300) trim(0.01) bs(300) thlevel(95) vce(cluster id)

 
  _matplot e(LR),columns(1 2) yline(7.3523, lpattern(dash)) recast(line) ///
                    ytitle("Likelihood Ratio") xtitle("Threshold Parameter") 

  di -2*log(1-(1-0.05)^(1/2))


xthreg lnco2 L.lnco2 ind rd lnei if in, rx(lneng) qx(age) thnum(2) grid(300) trim(0.01 0.05) bs(300 300) thlevel(95) gen(newvarname) noreg nobslog thgiven options

xthreg lnco2 L.lnco2 lnind lnrd1 lnsep lnurb if in, rx(lneng) qx(lnage) thnum(2) grid(300) trim(0.01 0.05) bs(300 300) thlevel(95) 

xthreg lp L.lp lnpgdp lnexp urb if in, rx(lnrd) qx(lnsep) thnum(2) grid(300) trim(0.01 0.05) bs(300 300) thlevel(95)

  _matplot e(LR21), columns(1 2) yline(7.3523, lpattern(dash)) recast(line) ///
                    ytitle("Likelihood Ratio") xtitle("1st Threshold Parameter") name(LR213)

  _matplot e(LR22), columns(1 2) yline(7.3523, lpattern(dash)) recast(line) ///
                    ytitle("Likelihood Ratio") xtitle("2nd Threshold Parameter") name(LR223)
  
  graph combine LR213 LR223, cols(1)